package com.leyou.user.service;

import com.leyou.user.mapper.AreasMapper;
import com.leyou.user.mapper.CityMapper;
import com.leyou.user.mapper.ProvinceMapper;
import com.leyou.user.pojo.Areas;
import com.leyou.user.pojo.City;
import com.leyou.user.pojo.Province;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {

    @Autowired
    private ProvinceMapper provinceMapper;

    @Autowired
    private CityMapper cityMapper;

    @Autowired
    private AreasMapper areasMapper;

    /**
     * 查询所有的省
     * @return
     */
    public List<Province> queryAllProvince() {
        return this.provinceMapper.selectAll();
    }

    /**
     * 根据省份id查询城市
     * @param pid
     * @return
     */
    public List<City> queryCityByProvinceId(String pid) {

        City city = new City();
        city.setProvinceid(pid);
        return this.cityMapper.select(city);

    }

    /**
     * 根据城市id查询县区
     * @param cid  城市id
     * @return
     */
    public List<Areas> queryAreasByCityId(String cid) {

        Areas areas = new Areas();
        areas.setCityid(cid);
        return this.areasMapper.select(areas);
    }
}
